# cython: language_level=3
from collections import defaultdict
import json
import logging
import time
from xml.dom import NotFoundErr
import numpy as np
import pandas as pd
from sanic.views import HTTPMethodView
from app.crawler.app_package import get_app_info

from utils.decorators import param_check
from utils.response import general_json_res

class GetAppInfo(HTTPMethodView):
    """restful接口实例"""
    
    async def get(self, request, pk=0):
        return general_json_res(404, "no get method.")

    async def post(self, request, pk=0):
        package_name = request.json.get("package_name")
        lang = request.json.get("lang")
        country = request.json.get("country")
        
        result = {}
        app_info = {}
        status = 200
        message = 'success'
        try:
            app_info = get_app_info.get_app_info(package_name, lang, country)
        except Exception as e:
            status = 500
            message = str(e)
            if message == 'App not found(404).' :
                status = 404
            
        result["app_info"] = app_info
        
        return general_json_res(status = status, msg = message, result=result)